<template>
  <j-modal :title="title" :width="width" :visible="visible" @ok="handleOk" @cancel="handleCancel" cancelText="关闭">
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="17" :lg="7" :md="8" :sm="24">
            <a-form-item :label="title">
              <a-input :placeholder="`请输入${title}`" style="width: 358px" v-model="queryParam[keyName]"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="7" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <a-table
      :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type: 'radio' }"
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      @change="handleTableChange"
    >
      <!-- <template slot="label" slot-scope="text">
        <j-ellipsis v-if="text.length > 20" :value="text" :length="20" />
        <span v-else>{{ text }}</span>
      </template> -->
    </a-table>
  </j-modal>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getAction } from '@/api/manage'
export default {
  name: 'BeefBooseRecordModal',
  mixins: [JeecgListMixin],
  data() {
    return {
      title: '',
      width: 800,
      visible: false,
      disableSubmit: false,
      disableMixinCreated: true,
      selectedRowKeys: [],
      columns: [],
      url: {
        list: '',
      },
      SelectData: {},
    }
  },
  props: {
    depurl: {
      type: String,
      default: '',
    },
    keyName: {
      type: String,
      default: 'keyword',
    },
  },
  mounted() {
    this.url.list = this.depurl
  },
  methods: {
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      // 加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams() // 查询条件
      this.loading = true
      // this.dataSource=[]
      this.selectedRowKeys = []
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          // update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          this.dataSource = res.result.records || res.result
          if (res.result.total) {
            this.ipagination.total = res.result.total
          } else {
            this.ipagination.total = 0
          }
          // update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false
      })
    },
    onSelectChange(selectedRowKeys, data) {
      console.log('selectedRowKeys changed: ', selectedRowKeys)
      console.log(data)
      this.selectedRowKeys = selectedRowKeys
      this.SelectData = data
    },
    show() {
      this.visible = true
      this.columns = [
        {
          title: '序号',
          dataIndex: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: this.title,
          dataIndex: 'label',
          scopedSlots: { customRender: 'label' },
        },
      ]
      this.loadData(1)
    },
    close() {
      this.$emit('close')
      this.queryParam = {}
      this.visible = false
    },
    handleOk() {
      this.$emit('getdata', this.SelectData)
      this.visible = false
      this.queryParam = {}
    },
    handleCancel() {
      this.close()
    },
  },
}
</script>